/*
 * p3507.cpp
 *
 *  Created on: 2013-5-30
 *      Author: zy
 */

#include<cstdio>
#include<iostream>
#include<cstring>
using namespace std;
const long long  INF=0xfffffffffff;
const int maxn=500010;
long long  f[maxn],s[maxn];
int a[maxn],m,n,l,r,q[maxn];
long long  min(long long x,long long y)
{
	return x<y?x:y;
}
double slope(int j,int k)
{
	if(s[j]==s[k])
	{
		if(f[j]>=f[k])return INF;
		else return -INF;
	}
	return (f[j]-f[k]+s[j]*s[j]-s[k]*s[k])/((double)s[j]-s[k]);
}
int main()
{
	while(scanf("%d%d",&n,&m)!=EOF)
	{
		memset(f,0,sizeof(f));
		memset(q,0,sizeof(q));
		s[0]=0;
		for(int i=1;i<=n;i++)
		{
			scanf("%d",&a[i]);
			s[i]=s[i-1]+a[i];
		}
		l=r=1;q[1]=0;
		for(int i=1;i<=n;i++)
		{
			while(l<r&&slope(q[l],q[l+1])<2*s[i])l++;
			f[i]=f[q[l]]+(s[i]-s[q[l]])*(s[i]-s[q[l]])+m;
			while(l<r&&slope(q[r-1],q[r])>slope(q[r],i))r--;
			r++;q[r]=i;
		}
		cout<<f[n]<<endl;
	}
	return 0;
}
